package com.suse.lhw.hms.exersiseserver.service.Impl;

import com.suse.lhw.hms.exersiseserver.domin.EMoventmodel;
import com.suse.lhw.hms.exersiseserver.pojo.out.EIAndName;
import com.suse.lhw.hms.exersiseserver.service.EMoventmodelService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import com.suse.lhw.hms.exersiseserver.domin.EMmInstance;
import com.suse.lhw.hms.exersiseserver.dao.EMmInstanceMapper;
import com.suse.lhw.hms.exersiseserver.service.EMmInstanceService;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * @ProjectName: health_manage_system
 * @Package: com.suse.lhw.hms.exersiseserver.service.Impl
 * @ClassName: EMmInstanceServiceImpl
 * @Description: java类作用描述
 * @Author: 李鸿炜
 * @CreateDate: 2020/5/3 13:59
 * @UpdateUser: 更新者
 * @UpdateDate: 2020/5/3 13:59
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
@Service
public class EMmInstanceServiceImpl implements EMmInstanceService {

    @Resource
    private EMmInstanceMapper eMmInstanceMapper;
    @Resource
    private EMoventmodelService eMoventmodelService;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return eMmInstanceMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(EMmInstance record) {
        return eMmInstanceMapper.insert(record);
    }

    @Override
    public int insertSelective(EMmInstance record) {
        return eMmInstanceMapper.insertSelective(record);
    }

    @Override
    public EMmInstance selectByPrimaryKey(Integer id) {
        return eMmInstanceMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(EMmInstance record) {
        return eMmInstanceMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(EMmInstance record) {
        return eMmInstanceMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<EIAndName> selectMovInstance() {
        String userId = "aaa";
        List<EIAndName> eiLIst = new ArrayList<EIAndName>();
        List<EMmInstance> mmInstanceList = eMmInstanceMapper.selectByUserId(userId);
        if (mmInstanceList == null || mmInstanceList.isEmpty()) {
            return null;
        }
        for (EMmInstance instance : mmInstanceList) {
            EMoventmodel eMoventmodel = eMoventmodelService.selectByPrimaryKey(instance.getMmid());
            EIAndName eiAndName = new EIAndName();
            eiAndName.setId(instance.getId());
            eiAndName.setMmid(instance.getMmid());
            eiAndName.setQuanity(instance.getQuanity());
            eiAndName.setUserid(instance.getUserid());
            //格式化日期
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            eiAndName.setCreatetime(simpleDateFormat.format(instance.getCreatetime()));
            eiAndName.setCalories(instance.getCalories());
            eiAndName.setType(instance.getType());
            eiAndName.setName(eMoventmodel.getMmName());
            eiAndName.setImgurl(eMoventmodel.getMmImgurl());
            eiLIst.add(eiAndName);
        }
        return eiLIst;
    }

}

